package MyBlog.dao.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Repository;

import MyBlog.dao.CommentDao;
import MyBlog.entity.Comment;

@Repository("commentDao")
public class CommentDaoImp implements CommentDao {

	@Autowired
	private HibernateTemplate hibernateTemplate;

	public List<Comment> getCommentsByArticleId(int articleId) {
		return (List<Comment>)hibernateTemplate.find("from Comment c where c.article.id = ?",articleId);
	}

	public void add(Comment comment) {
		hibernateTemplate.save(comment);
	}
	
	public static void main(String[] args) {
		ApplicationContext atx = new ClassPathXmlApplicationContext("beans.xml");
		CommentDao dao = (CommentDao) atx.getBean("commentDao");
		System.out.println(dao.getCommentsByArticleId(1).size());
	}
}
